﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
    /// <summary>
    /// 数据访问类:REGINFO
    /// </summary>
    public partial class REGINFO
    {
        private readonly GSLMS.Core.Loger log = new Core.Loger();
        public REGINFO()
        { }
        #region  Method
        /// <summary>
        ///  增加一条数据
        /// </summary>
        public bool Add(GSLMS.Entity.TB_APP_REGINFO model)
        {
            
            bool flag = false;
            OracleParameter[] parms = new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_CUSTNAME", model.CUSTNAME),
								new OracleParameter("P_CUSTNO", model.CUSTNO),
								new OracleParameter("P_LINKMAN", model.LINKMAN),
								new OracleParameter("P_LINKMANTEL", model.LINKMANTEL),
								new OracleParameter("P_SOURCE", model.SOURCE),
								new OracleParameter("P_SALESMANID", model.SALESMANID),
								new OracleParameter("P_SALESMAN", model.SALESMAN),
								new OracleParameter("P_MEDIATORID", model.MEDIATORID),
								new OracleParameter("P_MEDIATOR", model.MEDIATOR),
								new OracleParameter("P_FIELDPROJECT", model.FIELDPROJECT),
								new OracleParameter("P_BUSSTYPE", model.BUSSTYPE),
								new OracleParameter("P_PRODUCTID", model.PRODUCTID),
								new OracleParameter("P_PRODUCTNAME", model.PRODUCTNAME),
								new OracleParameter("P_LOANPHASE", model.LOANPHASE),
								new OracleParameter("P_LOANPHASETYPE", model.LOANPHASETYPE),
								new OracleParameter("P_REGDATE", model.REGDATE),
								new OracleParameter("P_REGMAN", model.REGMAN),
								new OracleParameter("P_INTEMTIONAMT", model.INTEMTIONAMT),
								new OracleParameter("P_IMPORTANTLEVEL", model.IMPORTANTLEVEL),
								new OracleParameter("P_REMARK", model.REMARK),
								new OracleParameter("P_LASTFLOWDATE", model.LASTFLOWDATE),
								new OracleParameter("P_STATUS", model.STATUS),
								new OracleParameter("P_ISSYSTEMSTOP", model.ISSYSTEMSTOP),
								new OracleParameter("P_STOPBY", model.STOPBY),
								new OracleParameter("P_STOPDATE", model.STOPDATE),
								new OracleParameter("P_DEPID", model.DEPID),
								new OracleParameter("P_DEPNAME", model.DEPNAME),
								new OracleParameter("P_SYSTEMID", model.SYSTEMID),
								new OracleParameter("P_MODIFYBY", model.MODIFYBY),
								new OracleParameter("P_MODIFYDATE", model.MODIFYDATE),
								new OracleParameter("P_DELETEFLAG", model.DELETEFLAG),
								new OracleParameter("P_DELETEBY", model.DELETEBY),
								new OracleParameter("P_DELETEDATE", model.DELETEDATE),
								new OracleParameter("P_SPAREFIELD1", model.SPAREFIELD1),
								new OracleParameter("P_SPAREFIELD2", model.SPAREFIELD2),
								new OracleParameter("P_SPAREFIELD3", model.SPAREFIELD3)};

            for (int i = 0; i < 37; i++)
            {
                parms[i].Direction = ParameterDirection.Input;
            }

            try
            {
                OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_reginfo_add", parms);
                flag = true;
            }
            catch (Exception ex)
            {
                log.ExceptionHand(ex);
            }
            return flag;
        }

        /// <summary>
        ///  更新一条数据
        /// </summary>
        public bool Update(GSLMS.Entity.TB_APP_REGINFO model)
        {
            bool flag = false;
            OracleParameter[] parms = new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_CUSTNAME", model.CUSTNAME),
								new OracleParameter("P_CUSTNO", model.CUSTNO),
								new OracleParameter("P_LINKMAN", model.LINKMAN),
								new OracleParameter("P_LINKMANTEL", model.LINKMANTEL),
								new OracleParameter("P_SOURCE", model.SOURCE),
								new OracleParameter("P_SALESMANID", model.SALESMANID),
								new OracleParameter("P_SALESMAN", model.SALESMAN),
								new OracleParameter("P_MEDIATORID", model.MEDIATORID),
								new OracleParameter("P_MEDIATOR", model.MEDIATOR),
								new OracleParameter("P_FIELDPROJECT", model.FIELDPROJECT),
								new OracleParameter("P_BUSSTYPE", model.BUSSTYPE),
								new OracleParameter("P_PRODUCTID", model.PRODUCTID),
								new OracleParameter("P_PRODUCTNAME", model.PRODUCTNAME),
								new OracleParameter("P_LOANPHASE", model.LOANPHASE),
								new OracleParameter("P_LOANPHASETYPE", model.LOANPHASETYPE),
								new OracleParameter("P_REGDATE", model.REGDATE),
								new OracleParameter("P_REGMAN", model.REGMAN),
								new OracleParameter("P_INTEMTIONAMT", model.INTEMTIONAMT),
								new OracleParameter("P_IMPORTANTLEVEL", model.IMPORTANTLEVEL),
								new OracleParameter("P_REMARK", model.REMARK),
								new OracleParameter("P_LASTFLOWDATE", model.LASTFLOWDATE),
								new OracleParameter("P_STATUS", model.STATUS),
								new OracleParameter("P_ISSYSTEMSTOP", model.ISSYSTEMSTOP),
								new OracleParameter("P_STOPBY", model.STOPBY),
								new OracleParameter("P_STOPDATE", model.STOPDATE),
								new OracleParameter("P_DEPID", model.DEPID),
								new OracleParameter("P_DEPNAME", model.DEPNAME),
								new OracleParameter("P_SYSTEMID", model.SYSTEMID),
								new OracleParameter("P_MODIFYBY", model.MODIFYBY),
								new OracleParameter("P_MODIFYDATE", model.MODIFYDATE),
								new OracleParameter("P_DELETEFLAG", model.DELETEFLAG),
								new OracleParameter("P_DELETEBY", model.DELETEBY),
								new OracleParameter("P_DELETEDATE", model.DELETEDATE),
								new OracleParameter("P_SPAREFIELD1", model.SPAREFIELD1),
								new OracleParameter("P_SPAREFIELD2", model.SPAREFIELD2),
								new OracleParameter("P_SPAREFIELD3", model.SPAREFIELD3)};

            for (int i = 0; i < 37; i++)
            {
                parms[i].Direction = ParameterDirection.Input;
            }

            try
            {
                OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_reginfo_update", parms);
                flag = true;
            }
            catch (Exception ex)
            {
                log.ExceptionHand(ex);
            }
            return flag;
        }

        /// <summary>
        ///  删除一条数据
        /// </summary>
        public bool Delete(GSLMS.Entity.TB_APP_REGINFO model)
        {
            bool flag = false;
            OracleParameter[] parms = new OracleParameter[]{
								new OracleParameter("P_ID", model.ID)};

            parms[0].Direction = ParameterDirection.Input;

            try
            {
                OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_reginfo_delete", parms);
                flag = true;
            }
            catch (Exception ex)
            {
                log.ExceptionHand(ex);
            }
            return flag;
        }

        /// <summary>
        ///DataRowToModel 
        /// </summary>
        public GSLMS.Entity.TB_APP_REGINFO DataRowToModel(DataRow dr)
        {
            if (dr != null && dr.ItemArray.Length > 0)
            {
                GSLMS.Entity.TB_APP_REGINFO model = new GSLMS.Entity.TB_APP_REGINFO();
              
                if (dr["ID"] != null && dr["ID"].ToString() != "")
                {
                    model.ID = OracleHelper.ToInt(dr["ID"].ToString());
                }
                if (dr["CUSTNAME"] != null && dr["CUSTNAME"].ToString() != "")
                {
                    model.CUSTNAME = dr["CUSTNAME"].ToString();
                }
                if (dr["CUSTNO"] != null && dr["CUSTNO"].ToString() != "")
                {
                    model.CUSTNO = dr["CUSTNO"].ToString();
                }
                if (dr["LINKMAN"] != null && dr["LINKMAN"].ToString() != "")
                {
                    model.LINKMAN = dr["LINKMAN"].ToString();
                }
                if (dr["LINKMANTEL"] != null && dr["LINKMANTEL"].ToString() != "")
                {
                    model.LINKMANTEL = dr["LINKMANTEL"].ToString();
                }
                if (dr["SOURCE"] != null && dr["SOURCE"].ToString() != "")
                {
                    model.SOURCE = dr["SOURCE"].ToString();
                }
                if (dr["SALESMANID"] != null && dr["SALESMANID"].ToString() != "")
                {
                    model.SALESMANID = OracleHelper.ToLong(dr["SALESMANID"].ToString());
                }
                if (dr["SALESMAN"] != null && dr["SALESMAN"].ToString() != "")
                {
                    model.SALESMAN = dr["SALESMAN"].ToString();
                }
                if (dr["MEDIATORID"] != null && dr["MEDIATORID"].ToString() != "")
                {
                    model.MEDIATORID = OracleHelper.ToLong(dr["MEDIATORID"].ToString());
                }
                if (dr["MEDIATOR"] != null && dr["MEDIATOR"].ToString() != "")
                {
                    model.MEDIATOR = dr["MEDIATOR"].ToString();
                }
                if (dr["FIELDPROJECT"] != null && dr["FIELDPROJECT"].ToString() != "")
                {
                    model.FIELDPROJECT = OracleHelper.ToInt(dr["FIELDPROJECT"].ToString());
                }
                if (dr["BUSSTYPE"] != null && dr["BUSSTYPE"].ToString() != "")
                {
                    model.BUSSTYPE = OracleHelper.ToInt(dr["BUSSTYPE"].ToString());
                }
                if (dr["PRODUCTID"] != null && dr["PRODUCTID"].ToString() != "")
                {
                    model.PRODUCTID = OracleHelper.ToLong(dr["PRODUCTID"].ToString());
                }
                if (dr["PRODUCTNAME"] != null && dr["PRODUCTNAME"].ToString() != "")
                {
                    model.PRODUCTNAME = dr["PRODUCTNAME"].ToString();
                }
                if (dr["LOANPHASE"] != null && dr["LOANPHASE"].ToString() != "")
                {
                    model.LOANPHASE = OracleHelper.ToInt(dr["LOANPHASE"].ToString());
                }
                if (dr["LOANPHASETYPE"] != null && dr["LOANPHASETYPE"].ToString() != "")
                {
                    model.LOANPHASETYPE = OracleHelper.ToInt(dr["LOANPHASETYPE"].ToString());
                }
                if (dr["REGDATE"] != null && dr["REGDATE"].ToString() != "")
                {
                    model.REGDATE = DateTime.Parse(dr["REGDATE"].ToString());
                }
                if (dr["REGMAN"] != null && dr["REGMAN"].ToString() != "")
                {
                    model.REGMAN = dr["REGMAN"].ToString();
                }
                if (dr["INTEMTIONAMT"] != null && dr["INTEMTIONAMT"].ToString() != "")
                {
                    model.INTEMTIONAMT = OracleHelper.ToDecimal(dr["INTEMTIONAMT"].ToString());
                }
                if (dr["IMPORTANTLEVEL"] != null && dr["IMPORTANTLEVEL"].ToString() != "")
                {
                    model.IMPORTANTLEVEL = dr["IMPORTANTLEVEL"].ToString();
                }
                if (dr["REMARK"] != null && dr["REMARK"].ToString() != "")
                {
                    model.REMARK = dr["REMARK"].ToString();
                }
                if (dr["LASTFLOWDATE"] != null && dr["LASTFLOWDATE"].ToString() != "")
                {
                    model.LASTFLOWDATE = DateTime.Parse(dr["LASTFLOWDATE"].ToString());
                }
                if (dr["STATUS"] != null && dr["STATUS"].ToString() != "")
                {
                    model.STATUS = OracleHelper.ToInt(dr["STATUS"].ToString());
                }
                if (dr["ISSYSTEMSTOP"] != null && dr["ISSYSTEMSTOP"].ToString() != "")
                {
                    model.ISSYSTEMSTOP = OracleHelper.ToInt(dr["ISSYSTEMSTOP"].ToString());
                }
                if (dr["STOPBY"] != null && dr["STOPBY"].ToString() != "")
                {
                    model.STOPBY = dr["STOPBY"].ToString();
                }
                if (dr["STOPDATE"] != null && dr["STOPDATE"].ToString() != "")
                {
                    model.STOPDATE = DateTime.Parse(dr["STOPDATE"].ToString());
                }
                if (dr["DEPID"] != null && dr["DEPID"].ToString() != "")
                {
                    model.DEPID = OracleHelper.ToLong(dr["DEPID"].ToString());
                }
                if (dr["DEPNAME"] != null && dr["DEPNAME"].ToString() != "")
                {
                    model.DEPNAME = dr["DEPNAME"].ToString();
                }
                if (dr["SYSTEMID"] != null && dr["SYSTEMID"].ToString() != "")
                {
                    model.SYSTEMID = OracleHelper.ToInt(dr["SYSTEMID"].ToString());
                }
                if (dr["MODIFYBY"] != null && dr["MODIFYBY"].ToString() != "")
                {
                    model.MODIFYBY = dr["MODIFYBY"].ToString();
                }
                if (dr["MODIFYDATE"] != null && dr["MODIFYDATE"].ToString() != "")
                {
                    model.MODIFYDATE = DateTime.Parse(dr["MODIFYDATE"].ToString());
                }
                if (dr["DELETEFLAG"] != null && dr["DELETEFLAG"].ToString() != "")
                {
                    model.DELETEFLAG = OracleHelper.ToInt(dr["DELETEFLAG"].ToString());
                }
                if (dr["DELETEBY"] != null && dr["DELETEBY"].ToString() != "")
                {
                    model.DELETEBY = dr["DELETEBY"].ToString();
                }
                if (dr["DELETEDATE"] != null && dr["DELETEDATE"].ToString() != "")
                {
                    model.DELETEDATE = DateTime.Parse(dr["DELETEDATE"].ToString());
                }
                if (dr["SPAREFIELD1"] != null && dr["SPAREFIELD1"].ToString() != "")
                {
                    model.SPAREFIELD1 = OracleHelper.ToInt(dr["SPAREFIELD1"].ToString());
                }
                if (dr["SPAREFIELD2"] != null && dr["SPAREFIELD2"].ToString() != "")
                {
                    model.SPAREFIELD2 = dr["SPAREFIELD2"].ToString();
                }
                if (dr["SPAREFIELD3"] != null && dr["SPAREFIELD3"].ToString() != "")
                {
                    model.SPAREFIELD3 = dr["SPAREFIELD3"].ToString();
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public GSLMS.Entity.TB_APP_REGINFO GetModel(decimal ID)
        {
            GSLMS.Entity.TB_APP_REGINFO sModel = new GSLMS.Entity.TB_APP_REGINFO();
            string sql = "";
            sql = "select * from TB_APP_REGINFO where id=" + ID;
            DataSet ds = OracleHelper.ExecuteDataset(sql);
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                sModel = DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
            return sModel;
        }

        /// <summary>
        /// 分页提取数据
        /// </summary>
        public List<GSLMS.Entity.TB_APP_REGINFO> GetList(GSLMS.Entity.TB_APP_REGINFO searchData, string strSort, int pageSize, int pageIndex, out int totalCount)
        {
            var list = new List<GSLMS.Entity.TB_APP_REGINFO>();
            DataTable dt = null;
            string tblName = "";
            string sqlWhere = "";
            string strFields = "*";
            int countFag = 0;


            dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFag, sqlWhere, out totalCount);
            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    GSLMS.Entity.TB_APP_REGINFO model = new GSLMS.Entity.TB_APP_REGINFO();
                    model = DataRowToModel(dt.Rows[i]);
                    list.Add(model);
                }
            }
            else
            {
                return null;
            }
            return list;
        }

        #endregion  Method
    }
}

